package com.example.homeworkdev.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.homeworkdev.R;
import com.example.homeworkdev.entity.Message;

import java.util.List;

public class MessageAdapter extends ArrayAdapter<Message>  {

    int resourceId;

    private List<Message> messageList;

    public MessageAdapter(@NonNull Context context, int resource, @NonNull List<Message> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        //存入选中的聊天基础信息
        Message people = getItem(position);
        View messageView = LayoutInflater.from(getContext()).inflate(resourceId,null);
        ImageView imageView = messageView.findViewById(R.id.img_message);
        TextView name = messageView.findViewById(R.id.text_name);
        TextView message = messageView.findViewById(R.id.text_message);
        imageView.setImageResource(people.getImg());
        name.setText(people.getName());
        message.setText(people.getMesssage());



        return messageView;
    }
}
